package edu.gyc.objecthomework;

/**

 File name: YearsToOvertakePhase2.java

 This program is the second step towards a final solution.
  It includes comments that outline the entire solution,
  reads in two species,
  determines which has the lower initial population,
  prints out the name, population and growth rate for the
      species with the lower population,
  followed by the name, population and growth rate for the
      species with the higher population,
  then enters a loop that prints out the new populations of both
      species for each year for ten years.

 This program is useful for experimenting with input values to find
  test cases (specific input data) that will result in a variety
  of situations to test the final version, e.g.
      What values of initial populations and growth rates will
          make lower overtake more in just one year?
      What values of initial populations and growth rates will
          make lower overtake more in less than ten years?
      What values of initial populations and growth rates will
          make lower overtake more in exactly ten years?
      What values of initial populations and growth rates will
          not make lower overtake more in ten years?


 When this program is complete it will do the following and have the
  postconditions stated below:
  Read in the names, populations and growth rates for two
  species and calculate the number of years it will take the one
  with the lower population to overtake the other (or a message that
  it will never have a higher population).

 Preconditions:
  none

 Postconditions:
  Displays either the number of years it takes for the species with the lower
  population to have a population greater than the other,
  or a message that it will not exceed the other

 Author: Lew Rakocy
 email address: Lrakocy@devrycols.edu
 Date: <2/20/99>
 Last changed: 8/26/00 Changed method calls to those in the newer
		version of Species.

*/

 public class YearsToOvertakePhase2
 {
    public static void main(String[] args)
    {
       Species s1 = new Species();
       Species s2 = new Species();
       Species lower = new Species(); // has lower initial population
       Species higher = new Species(); // has higher initial population

       // read in one species
       s1.readInput();

       // read in second species
       s2.readInput();

       // special condition detection:
       // What if they have the same initial populations?

       // determine which has the lower population
       if(s1.getPopulation() < s2.getPopulation())
       {
           lower.set(s1.getName(), s1.getPopulation(),
                     s1.getGrowthRate());
           higher.set(s2.getName(), s2.getPopulation(),
                      s2.getGrowthRate());
       }
       else
       {
           lower.set(s2.getName(), s2.getPopulation(),
                     s2.getGrowthRate());
           higher.set(s1.getName(), s1.getPopulation(),
                      s1.getGrowthRate());
       }

       // test: these lines can be deleted after this second stage program works
       System.out.println("The species that has the lower "
              + "initial population is");
       lower.writeOutput();
       System.out.println("The species with the higher population is");
       higher.writeOutput();
       // end of test

       // find number of years it takes for the species with lower initial
       // population to overtake the other speceis.
       int years = 1;
       while (years <= 10)
       {
          // test: the next line can be deleted after
          // second stage program works
          System.out.println("After " + years + " years, Lower pop = "
                 + lower.projectedPopulation(years));

          // test: the next line can be deleted after
          // second stage program works
          System.out.println("After " + years + " years, Higher pop = "
                 + higher.projectedPopulation(years));
          years++;
       }
       // Be careful when years = 10:
       // "lower" may or may not have overtaken "higher"
       //  so you must do a final check:
       //    if(years = 10 && popSmaller <= popLarger)
       //      print "lower never overtakes higher"
       //    else print "lower overtakes higher after x years"
    }
 }

